/*
 * This file is part of LexiToolsMobile
 *  
 * Author: Jerzy Wawro
 * ver. 1.00
 * Copyright: Tenar (http://www.tenar.pl)
 *
 * Mobile LexiTools is an open source project; you can redistribute it 
 * and/or modify it under the terms of the license as published -  GPL with 
 * the following modification:  fragments of the code may be not copyleft 
 * (hidden), to protect contents of the dicionaries.
 * In this case the author of non-public fragments of the code is obliged 
 * to make available functionally equivalent code for unprotected dictionaries.
 * 
 * Mobile LexiTools is distributed WITHOUT ANY WARRANTY.
 * See the license for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with LexiToolsMobile (see: gpl.txt); if not - you can find it 
 * on web page http://www.fsf.org/, or write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

     
package lt.util;

public class device {

    static final public int iPLATFORM_OTHER = 0;
    static final public int iPLATFORM_NOKIA = 1;
    static final public int iPLATFORM_SONY_ERICSSON = 2;
    static final public int iPLATFORM_SAMSUNG = 3;
    static final public int iPLATFORM_SIEMENS = 4;
    static final public int iPLATFORM_MOTOROLA = 5;
    

    public static int platform() {
        try {
            final String currentPlatform = System.getProperty("microedition.platform");
            if (currentPlatform.indexOf("Nokia") != -1) {
                return iPLATFORM_NOKIA;
            } else if (currentPlatform.indexOf("SonyEricsson") != -1) {
                return iPLATFORM_SONY_ERICSSON;
            }
        } catch (Throwable ex) {
        }        
        try {
            Class.forName("com.siemens.mp.game.Light");
            return iPLATFORM_SIEMENS;
        } catch (Exception ex) {
        }
        try {
            /* if this class is found, the phone is a samsung phone */
            Class.forName("com.samsung.util.Vibration");
            return iPLATFORM_SAMSUNG;
        } catch (Exception ex) {
        }
        try {
            Class.forName("com.motorola.multimedia.Vibrator");
            return iPLATFORM_MOTOROLA;
        } catch (Throwable ex) {
            try {
                Class.forName("com.motorola.graphics.j3d.Effect3D");
                return iPLATFORM_MOTOROLA;
            } catch (Throwable ex2) {
                try {
                    Class.forName("com.motorola.multimedia.Lighting");
                    return iPLATFORM_MOTOROLA;
                } catch (Throwable ex3) {
                    try {
                        Class.forName("com.motorola.multimedia.FunLight");
                        return iPLATFORM_MOTOROLA;
                    } catch (Throwable ex4) {
                    }
                }
            }
        }
        return iPLATFORM_OTHER;

/*
        try {
            if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA).toUpperCase().indexOf(SOFT_WORD) > -1) {
                return PLATFORM_MOTOROLA;
            }
        } catch (Throwable e) {
            try {
                if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA1).toUpperCase().indexOf(SOFT_WORD) > -1) {
                    return PLATFORM_MOTOROLA;
                }
            } catch (Throwable e1) {
                try {
                    if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA2).toUpperCase().indexOf(SOFT_WORD) > -1) {
                        return PLATFORM_MOTOROLA;
                    }
                } catch (Throwable e2) {
                }
            }
        }
 */       
    }
    
    /*    
     
     // detecting SIEMENS
        try {
            Class.forName("com.siemens.mp.io.File");
            return PLATFORM_SIEMENS;
        } catch (Throwable ex) {
        }
        // detecting LG
        try {
            Class.forName("mmpp.media.MediaPlayer");
            return PLATFORM_LG;
        } catch (Throwable ex) {
            try {
                Class.forName("mmpp.phone.Phone");
                return PLATFORM_LG;
            } catch (Throwable ex1) {
                try {
                    Class.forName("mmpp.lang.MathFP");
                    return PLATFORM_LG;
                } catch (Throwable ex2) {
                    try {
                        Class.forName("mmpp.media.BackLight");
                        return PLATFORM_LG;
                    } catch (Throwable ex3) {
                    }
                }
            }
        }
        return PLATFORM_NOT_DEFINED;
    }
*/

    public static String getPhoneType() {
        try {
            return System.getProperty("microedition.platform");
        } catch(Exception ex) {
            return "Unknown";
        }
    }

    
    public static String getIMEI() {
        int p;
        
        p=platform();
        switch (p) {
            case iPLATFORM_NOKIA: return System.getProperty("com.nokia.IMEI") /*System.getProperty("phone.imei");*/; 
            case iPLATFORM_SONY_ERICSSON: return System.getProperty("com.sonyericsson.imei");
            case iPLATFORM_SAMSUNG: return System.getProperty("com.samsung.imei");
            case iPLATFORM_SIEMENS: return System.getProperty("com.siemens.IMEI"); 
            case iPLATFORM_MOTOROLA: return System.getProperty("com.motorola.IMEI") /*System.getProperty("IMEI");*/;
            case iPLATFORM_OTHER: return System.getProperty("IMEI");
        }
        return "?";
    }
    

}
